package com.koudai.reader.util;

import android.content.Context;
import android.graphics.Color;
import android.text.Html;
import android.view.Gravity;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class MyToast extends Toast {

    public MyToast(Context context, String message, int textsize) {
        super(context);
        if (context == null) {
            return;
        }

        RelativeLayout mainLayout = new RelativeLayout(context);

        RelativeLayout.LayoutParams mainP = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        mainLayout.setLayoutParams(mainP);
        mainLayout.setBackgroundColor(Color.BLACK);
        TextView content = new TextView(context);
        RelativeLayout.LayoutParams contentP = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
                RelativeLayout.LayoutParams.WRAP_CONTENT);
        content.setLayoutParams(contentP);
        content.setText(Html.fromHtml(message));
        content.setTextSize(textsize);
        content.setTextColor(Color.WHITE);
        content.setGravity(Gravity.CENTER);
        mainLayout.addView(content);

        setGravity(Gravity.CENTER | Gravity.BOTTOM, 0, Utils.convertToScreenPixels(300));
        setDuration(Toast.LENGTH_SHORT);
        setView(mainLayout);

    }

}
